package com.cykj.pos.controller.api;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.domain.CustomerCashBackTemp;
import com.cykj.pos.service.ICustomerCashBackTempService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * 商户刷满返现模板Controller
 *
 * @author weijianbo
 * @date 2025-03-19
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/temp" )
public class CustomerCashBackTempController extends BaseController {

    private final ICustomerCashBackTempService iCustomerCashBackTempService;

    /**
     * 查询商户刷满返现模板列表
     */
    @PreAuthorize("@ss.hasPermi('pos:temp:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerCashBackTemp customerCashBackTemp) {
        startPage();
        List<CustomerCashBackTemp> list = iCustomerCashBackTempService.queryList(customerCashBackTemp);
        return getDataTable(list);
    }

    /**
     * 导出商户刷满返现模板列表
     */
    @PreAuthorize("@ss.hasPermi('pos:temp:export')" )
    @Log(title = "商户刷满返现模板" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CustomerCashBackTemp customerCashBackTemp) {
        List<CustomerCashBackTemp> list = iCustomerCashBackTempService.queryList(customerCashBackTemp);
        ExcelUtil<CustomerCashBackTemp> util = new ExcelUtil<CustomerCashBackTemp>(CustomerCashBackTemp.class);
        return util.exportExcel(list, "temp" );
    }

    /**
     * 获取商户刷满返现模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:temp:query')" )
    @GetMapping(value = "/{tempId}" )
    public AjaxResult getInfo(@PathVariable("tempId" ) Long tempId) {
        return AjaxResult.success(iCustomerCashBackTempService.getById(tempId));
    }

    /**
     * 新增商户刷满返现模板
     */
    @PreAuthorize("@ss.hasPermi('pos:temp:add')" )
    @Log(title = "商户刷满返现模板" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerCashBackTemp customerCashBackTemp) {
        return toAjax(iCustomerCashBackTempService.save(customerCashBackTemp) ? 1 : 0);
    }

    /**
     * 修改商户刷满返现模板
     */
    @PreAuthorize("@ss.hasPermi('pos:temp:edit')" )
    @Log(title = "商户刷满返现模板" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerCashBackTemp customerCashBackTemp) {
        return toAjax(iCustomerCashBackTempService.updateById(customerCashBackTemp) ? 1 : 0);
    }

    /**
     * 删除商户刷满返现模板
     */
    @PreAuthorize("@ss.hasPermi('pos:temp:remove')" )
    @Log(title = "商户刷满返现模板" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{tempIds}" )
    public AjaxResult remove(@PathVariable Long[] tempIds) {
        return toAjax(iCustomerCashBackTempService.removeByIds(Arrays.asList(tempIds)) ? 1 : 0);
    }
}
